Page({
  data: {
    showModal: true,
    weekLength: 7,
    week: ["日", "一", "二", "三", "四", "五", "六"],
    dayList: [],
    weekNum: 0,
    tapThis: 0,
    thisMonth: 0,
    thisYear: 0,
    dayIndex: 0,
    chooseDate: ""
  },

  getWeek(year, month, day) {
    var that = this;
    var d = new Date();
    d.setFullYear(year);
    d.setMonth(month - 1);
    d.setDate(1);
    var n = d.getDay();
    var arr = [];
    var Index = 0;
    var dayN = 1;

    for (var i = 0; i < day; i++) {
      arr.push(dayN++);
    }

    var now = new Date();
    var nowYear = now.getFullYear();
    var nowMonth = now.getMonth() + 1;
    var nowDay = now.getDate();
    var val = 1;

    if (year == nowYear) {
      if (month == nowMonth) {
        Index = arr.indexOf(nowDay);
        console.log(Index);
        val = nowDay;
      }
    }

    that.setData({
      weekNum: n,
      dayList: arr,
      dayIndex: Index,
      tapThis: Index,
      thisMonth: month,
      thisYear: year,
      chooseDate: year + "-" + month + "-" + val
    });
  },

  chooseDate(e) {
    var that = this;
    var n = e.currentTarget.dataset.index;
    var val = e.currentTarget.dataset.value;
    console.log(n);

    if (n >= that.data.dayIndex) {
      that.setData({
        tapThis: n,
        chooseDate: that.data.thisYear + "-" + that.data.thisMonth + "-" + val,
        showModal: true
      });
    }
  },

  /** 
  * 弹出框蒙层截断touchmove事件 
  */
  preventTouchMove: function () {},

  /** 
   * 隐藏模态对话框 
   */
  hideModal() {
    var that = this;
    that.setData({
      showModal: true
    });
  },

  showModalBtn() {
    var that = this;
    that.setData({
      showModal: false
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    var that = this;
    that.getWeek("2018", "04", "31"); //使用方法： 在此函数内传入年、月、日(此月的天数)即可。
  }
});